package org.androidpush.activity;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.androidpush.R;
import org.androidpush.client.Constants;
import org.androidpush.greendao.DaoMaster;
import org.androidpush.greendao.DaoSession;
import org.androidpush.greendao.Schedule;
import org.androidpush.greendao.ScheduleDao;
import org.androidpush.greendao.UserFriendDao;

import java.util.List;

/**
 * Created by huang on 2017/4/17 0017.
 */
public class SimpleActivity extends Activity{

    private DaoMaster master;
    private DaoSession session;
    private SQLiteDatabase db;

    private ScheduleDao scheduDao;
    private UserFriendDao userFriendDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml_chat);
        openDB();
        delete();

       /* LinearLayout linearLayout = (LinearLayout) findViewById(R.id.id_schedule_week1);
        final TextView showText = new TextView(this);
        showText.setTextColor(Color.GREEN);
        showText.setTextSize(30);
//            showText.setId();
        showText.setText("simple");
        showText.setBackgroundColor(Color.GRAY);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(10, 10, 10, 10);
        showText.setLayoutParams(lp);
        linearLayout.addView(showText);*/
    }



    private void openDB(){
        db = new DaoMaster.DevOpenHelper(SimpleActivity.this, Constants.SHARED_SQLITEDB_NAME,null).getWritableDatabase();
        master = new DaoMaster(db);
        session = master.newSession();
        scheduDao = session.getScheduleDao();
        userFriendDao = session.getUserFriendDao();
    }

    private void addSchedu(){
        Schedule schedu = new Schedule();
        schedu.setCouName("C++");
        scheduDao.insert(schedu);
    }

    private void delete(){
        scheduDao.deleteAll();
    }

    private void queryAll(){
        List<Schedule> schedus = scheduDao.queryBuilder().list();
    }

    private void update(){
        Schedule schedu = new Schedule();
        schedu.setCouName("C++");
        scheduDao.insertOrReplace(schedu);
    }
}
